<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no, width=device-width">
    <link rel="shortcut icon" href="/static/app_link/{$data.app}_favicon_16.ico">
    <link href="/static/app_link/app_link.css" rel="Stylesheet" type="text/css">
    <script src="/static/app_link/jquery-1.7.1.min.js" type="text/javascript"></script>
    {if $signPackage.appId!=''}
    <script src="/static/app_link/jweixin-1.6.0.js"></script>
    {/if}
    <script>
        (function (w, d, s, q, i) {
            w[q] = w[q] || [];
            var f = d.getElementsByTagName(s)[0], j = d.createElement(s);
            j.async = true;
            j.id = 'beacon-aplus';
            j.src = 'https://d.alicdn.com/alilog/mlog/aplus/' + i + '.js';
            f.parentNode.insertBefore(j, f);
        })(window, document, 'script', 'aplus_queue', '203467608');

        //集成应用的appKey
        aplus_queue.push({
            action: 'aplus.setMetaInfo',
            arguments: ['appKey', '65ed16293ace4f7d719768ef']
        });
        //是否开启调试模式
        aplus_queue.push({
            action: 'aplus.setMetaInfo',
            arguments: ['DEBUG', parseInt('{$debug}') === 1]
        });
        /******************************************************************/
    </script>
    <script type="text/javascript">

        const error_msg = '{$error_msg}';
        const app = '{$data.app}';
        const target = '{$data.target}';
        const link = '{$data.link}';
        const download_url_ios = '{$data.download_urls.ios}';
        const download_url_android = '{$data.download_urls.android}';

        var tempPageObj = {}
        tempPageObj.mobileSchemeUrl = app + "://jump?target=" + target + "&link=" + link;
        tempPageObj.fullUrl = ""

        //微信配置
        tempPageObj.debugMode = parseInt('{$debug}') === 1;
        tempPageObj.appId = "{$signPackage.appId}";
        tempPageObj.timestamp = "{$signPackage.timestamp}";
        tempPageObj.nonceStr = "{$signPackage.nonceStr}";
        tempPageObj.signature = "{$signPackage.signature}";
        //分享数据
        tempPageObj.title = "{$share_data.title}";
        tempPageObj.introduction = "{$share_data.introduction}";
        tempPageObj.img = "{$share_data.img}";
        tempPageObj.url = "{$share_data.url}";
        let isWxOpenLunchApp = false;
        if (tempPageObj.appId) {
            isWxOpenLunchApp = true;
            console.log('在微信里', JSON.stringify('{$signPackage.signature}'));
        }

        if (tempPageObj.debugMode) {
            console.log("调试模式开启", tempPageObj.debugMode)
            console.log('params app=', app, 'target=', target, 'link=', link);
            const referrer = document.referrer;
            console.log('referrer=', referrer);
            console.log('debug=', parseInt('{$debug}') === 1)
        }

        // var isWxOpenLunchApp = false;
        $(function () {
            openApp(tempPageObj);
        })
    </script>
    <title>{$data.app_name}</title></head>
<body style="padding: 0;background: {$data.color_bg}">
<form id="form1">
    <!--下载提示alert-->
    <div id="DownLoadTip" class="copymask tips" style="display: none;">
        <div id="copytip" class="copytip">
            <div>
                <img class="closeBtn" onclick="javascript:closeDownLoadTip();return false;"
                     src="/static/app_link/close.png">
            </div>
            <div class="copyTipTitle">无法打开？</div>
            <div class="copyTipContent">
                可能是当前应用不支持唤醒我们，如果您尚未安装{$data.app_name}，点击立即下载试试吧~
            </div>
            <div style="background: #FFFFFF;box-shadow: 0 0 0 0 #EEEEEE;border-radius: 0 0 4px 4px; margin: 25px 1px 0 1px;border-top: 1px solid #eeeeee;">
                <span class="cancelBtn" onclick="javascript:closeDownLoadTip();return false;">取消</span>
                <span class="downloadBtn" style="color:{$data.color_btn};" onclick="javascript:download();closeDownLoadTip();return false;">立即下载</span>
            </div>
        </div>
    </div>
    <!--浏览器打开提示-->
    <div id="tip" class="copymask tips" style="background: rgba(0, 0, 0, 0.75); display: none;">
        <div style="position:fixed;top:9px;right: 12px;">
            <img id="tipsImg" width="375px" height="140px" src="/static/app_link/browser_ios_tip.png">
        </div>
    </div>
    <!--异常提示-->
    <div id="errorTips" class="tips" style="display: none;">
        <div style="text-align: center; margin: 10px auto;">
            <img style="height: 80px;" src="/static/app_link/error.png">
        </div>
        <div style="text-align: center; font-size: 16px;">{$error_msg}</div>
    </div>
    <!--立即打开按钮-->
    <div id="wxOpenLunchApp">
        <div style="text-align: center;">
            <img style="display:block; width: 100%" src="/static/app_link/bg_{$data.app}.png">
            <wx-open-launch-app style="width: 100%; display: none;" id="wx-launch-btn" appid="{$data.app_id_wechat}"
                                extinfo='{$data.app}://jump?target={$data.target}&link={$data.link}'>
                <template>
                    <style>
                        .btn {
                            outline: none;
                            border: 1px solid #FFF;
                            width: 80%;
                            color: #FFF;
                            background: #00D8D3;
                            font-size: 18px;
                            line-height: 40px;
                            height: 40px;
                            font-weight: bold;
                            border-radius: 20px;
                            margin: 13px auto 15px auto;
                        }
                    </style>
                    <button class="btn hiddenDiv active" style="display: block;background: {$data.color_btn};">
                        立即打开
                    </button>
                </template>
            </wx-open-launch-app>
            <button id="openNow" class="refresh hiddenDiv active" style="background: {$data.color_btn};">
                立即打开
            </button>
            <div id="downloadDiv"
                 style="display: block; font-size: 14px; color: rgb(146, 146, 146); margin-bottom: 30px; line-height: 20px;">如未安装请点击下载<br>
                如已安装未自动跳转，请&nbsp;<a id="downloadButton" style="font-size: 18px;text-decoration: none; color: {$data.color_btn};"
                                    class="active">立即下载</a>
            </div>
        </div>
    </div>
</form>
<script src="/static/app_link/app_link.js"></script>
<script>
    document.addEventListener('WeixinOpenTagsError', function (e) {
        console.error('WeixinOpenTagsError:', e.detail.errMsg); // 无法使用开放标签的错误原因，需回退兼容。仅无法使用开放标签，JS-SDK其他功能不受影响
    });
    var btn = document.getElementById('wx-launch-btn');
    btn.addEventListener('launch', function (e) {
        console.log('wx-launch-btn addEventListener launch:', e);
    });
    btn.addEventListener('error', function (e) {
        console.log('wx-launch-btn addEventListener error');
        if (e.detail.errMsg === "launch:fail") {
            console.log('微信运行失败', e)
            alert('微信运行失败:' + JSON.stringify(e));
            alert('微信运行失败2:' + JSON.stringify(e.detail));
            var tip = document.getElementById('tip')
            var tipsImg = document.getElementById('tipsImg')
            if (isIOS) {
                tipsImg.src = "/static/app_link/browser_ios_tip.png"
            } else {
                tipsImg.src = "/static/app_link/browser_android_tip.png"
            }
            tip.style.display = "block";
            setTimeout(function () {
                tip.style.display = "none";
            }, 3000);
        }
    });
</script>

</body>
</html>
